package com.holic.spring.custom.service;

import com.holic.spring.custom.annotation.Argument;
import com.holic.spring.custom.annotation.Arguments;
import com.holic.spring.custom.annotation.GraphQLComponent;
import com.holic.spring.custom.annotation.GraphQLMapping;
import com.holic.spring.custom.holder.DataHolder;
import com.holic.spring.custom.model.User;
import graphql.com.google.common.collect.Lists;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName ProjectService
 * @Description
 * @Author Neil
 * @Date 2024/11/14 11:08
 * @Version V1.0
 **/
@GraphQLComponent
@Service
public class UserService {

    /**
     * 根据用户ID获取用户信息
     * @return
     */
    @GraphQLMapping
    public User getUserById(@Argument String id, String name){
        System.out.println("----------getUserById:" + Thread.currentThread().getId());
        User user = new User();
        user.setId("111");
        user.setName("xxxholic");
        user.setAge(22);
        return user;
    }

    @GraphQLMapping
    public List<User> getUserByIds(@Argument List ids, String name){
        System.out.println(DataHolder.get());
        System.out.println("----------getUserByIds:" + Thread.currentThread().getId());
        List list = Lists.newArrayList();
        User user = new User();
        user.setId("111");
        user.setName("xxxholic");
        user.setAge(22);
        list.add(user);
        return list;
    }

    @GraphQLMapping
    public User getUserByIdAndName(@Arguments User example, @Argument String id, String age, @Argument("name") String name){
        System.out.println("----------getUserByIdAndName:" + Thread.currentThread().getId());
        User user = new User();
        user.setId("111");
        user.setName("xxxholic");
        user.setAge(22);
        return user;
    }

    @GraphQLMapping
    public User getUserByExample(@Argument User example){
        User user = new User();
        user.setId("111");
        user.setName("xxxholic");
        user.setAge(22);
        return user;
    }

    @GraphQLMapping
    public List getUserList(){
        List list = Lists.newArrayList();
        User user = new User();
        user.setId("111");
        user.setName("xxxholic");
        user.setAge(22);
        list.add(user);
        return list;
    }

    @GraphQLMapping(typeName = GraphQLMapping.MUTATION)
    public List<User> createUsers(@Argument List<User> users){
        if(1 == 1){
            throw new RuntimeException("调用错误");
        }
        return users;
    }

}
